package com.zengdada.authority.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 12614
 */
public class DateUtil {

    /**
     * 字符串转换成日期
     *
     * @param dataStr
     * @return
     */
    public static Date StringConvertToDate(String dataStr) {
        return StringConvertToDate(dataStr, "yyyy-MM-dd HH:mm:ss");
    }

    public static Date StringConvertToDate(String dataStr, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        try {
            return sdf.parse(dataStr);
        } catch (ParseException e) {
            e.printStackTrace();
            return new Date();
        }
    }

    /**
     * 日期转换成字符串
     *
     * @param dt
     * @return
     */
    public static String DateConvertToString(Date dt) {
        return DateConvertToString(dt, "yyyy-MM-dd HH:mm:ss");

    }

    public static String DateConvertToString(Date dt, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(dt);
    }


}